import { stringify } from 'qs';
import request from '@/utils/request';
import apiPath from '@/configs/api.map';

const {
  api_editPermission,
  api_deletePermission,
  api_queryPermissions,
  api_queryPermissionsInfo,
  api_queryPermissionsTypeList,
  api_getApis,
  api_getPermissionApis,
  api_savePermissionApis,
  api_queryAuthApis,
  api_checkMFA,
  api_getMFAQrCode,
  api_saveApInfo,
  api_deleteApi,
  api_bindMFA,
  api_getApiGroups,
  api_addApiGroup,
  api_delApiGroup,
} = apiPath;
/**
 * @description 添加权限
 * @author songs
 * @date 2019-08-27
 * @export
 * @param {*} params
 * @returns
 */
export async function addPermission(params) {
  return request(api_editPermission, {
    method: 'POST',
    data: params,
  });
}
/**
 * @description 编辑权限
 * @author songs
 * @date 2019-08-27
 * @export
 * @param {*} params
 * @returns
 */
export async function editPermission(params) {
  return request(api_editPermission, {
    method: 'POST',
    data: params,
  });
}
/**
 * @description 删除权限
 * @author songs
 * @date 2019-08-27
 * @export
 * @param {*} params
 * @returns
 */
export async function deletePermission(params) {
  return request(api_deletePermission, {
    method: 'POST',
    data: params,
  });
}

/**
 * @description 获取权限树
 * @author songs
 * @date 2019-08-27
 * @export
 * @param {*} params
 * @returns
 */
export async function queryPermissionsList(params) {
  return request(`${api_queryPermissions}?${stringify(params)}`);
}

/**
 * @description 获取权限详情
 * @author songs
 * @date 2019-08-27
 * @export
 * @param {*} params
 * @returns
 */
export async function queryPermissionsInfo(params) {
  return request(`${api_queryPermissionsInfo}?${stringify(params)}`);
}

/**
 * @description 获取权限类型列表
 * @author songs
 * @date 2019-08-27
 * @export
 * @param {*} params
 * @returns
 */
export async function queryPermissionsTypeList(params) {
  return request(`${api_queryPermissionsTypeList}?${stringify(params)}`);
}

// 获取接口列表 /admin/api/AM-032
export async function getApis(params) {
  return request(`${api_getApis}`, {
    method: 'POST',
    data: params || { current: 1, pageSize: 1000 },
  });
}

// 根据权限id查询全部接口列表 /admin/api/AM-033
export async function getPermissionApis(params) {
  return request(`${api_getPermissionApis}?${stringify(params)}`);
}

// 分配接口 /admin/api/AM-034
export async function savePermissionApis(params) {
  return request(`${api_savePermissionApis}`, {
    method: 'POST',
    data: params,
  });
}

export async function queryAuthApis(params) {
  return request(api_queryAuthApis, {
    method: 'POST',
    data: params,
  });
}

export async function bindMFA(params) {
  return request(api_bindMFA, {
    method: 'POST',
    data: params,
  });
}

export async function checkMFA(params) {
  return request(api_checkMFA, {
    method: 'POST',
    data: params,
  });
}

export async function getMFAQrCode(params = {}) {
  return request(`${api_getMFAQrCode}?${stringify(params)}`);
}

export async function saveApInfo(params = {}) {
  return request(api_saveApInfo, {
    method: 'POST',
    data: params,
  });
}

export async function deleteApi(params = {}) {
  return request(`${api_deleteApi}?${stringify(params)}`);
}

export async function getApiGroups(params = {}) {
  return request(api_getApiGroups, {
    method: 'POST',
    data: params,
  });
}

export async function addApiGroup(params = {}) {
  return request(api_addApiGroup, {
    method: 'POST',
    data: params,
  });
}

export async function delApiGroup(params = {}) {
  return request(`${api_delApiGroup}?${stringify(params)}`);
}
